package com.sense.kukoo.biz_messages.adapter.provider

import android.widget.ImageView
import android.widget.TextView
import com.sense.kukoo.biz_messages.R
import com.sense.kukoo.biz_messages.adapter.MessagesItemAdapter
import com.sense.kukoo.common.repo.biz.MessagesItemBean
import com.sense.kukoo.common.repo.http.bean.UserMessageSystemBean
import com.sense.kukoo.common.utils.DataTimeUtil
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder

class SystemsMessagesItemProvider(
    val listener: MessagesItemAdapter.MessagesItemListener,
): MultiItemProvider<MessagesItemBean>() {

    override fun getItemType(): Int = MessagesItemBean.TYPE_SYSTEMS

    override fun getItemLayoutId(): Int = R.layout.biz_messages_item_systems

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: MessagesItemBean) {
        val data: UserMessageSystemBean = item.system!!
        //
        val tv_time = viewHolder.getView(R.id.tv_time) as TextView
        tv_time.text = DataTimeUtil.dateTransform2(data.createdAt)
        //
        val iv_icon = viewHolder.getView(R.id.iv_icon) as ImageView
        when (data.type) {
            4 -> {
                iv_icon.setImageResource(com.sense.kukoo.common_design.R.drawable.design_logo_messages_system)
            }
            5 -> {
                iv_icon.setImageResource(com.sense.kukoo.common_design.R.drawable.design_logo_messages_creator)
            }
        }
        //
        val tv_messages_text = viewHolder.getView(R.id.tv_messages_text) as TextView
        tv_messages_text.text = data.content
    }
}